package org.example.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.example.pojo.DRole;
import org.example.pojo.select.DRoleSelect;
import org.example.service.DRoleService;
import org.example.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@CrossOrigin(origins = "*")
@RestController
@RequestMapping("role")
@Tag(name = "角色数据API",description = "Role Controller")
public class DRoleController {

    @Autowired
    private DRoleService dRoleService;

    /**
     * 搜索全部角色信息
     * @param dRoleSelect 角色搜索值
     * @return 无
     */
    @Operation(summary = "搜索全部角色信息")
    @PostMapping("/selectAll")
    public Result<Map> SelectAll(@RequestBody DRoleSelect dRoleSelect){
        return dRoleService.SelectAllRoles(dRoleSelect);
    }

    /**
     * 添加角色
     * @param dRoleSelect 添加的角色
     * @return 无
     */
    @Operation(summary = "添加角色")
    @PostMapping("/addRole")
    public Result<Map> AddRole(@RequestBody DRoleSelect dRoleSelect){
        return dRoleService.AddRole(dRoleSelect);
    }

    /**
     * 更新角色状态
     * @param dRole 提供的角色
     * @return 无
     */
    @Operation(summary = "更新角色状态")
    @PostMapping("/updateRoleState")
    public Result<Map> UpdateRoleState(@RequestBody DRole dRole){
        return dRoleService.UpdateRoleState(dRole);
    }

    /**
     * 删除角色
     * @param dRole 提供的角色
     * @return 无
     */
    @Operation(summary = "删除角色")
    @PostMapping("/deleteRole")
    public Result<Map> DeleteRole(@RequestBody DRole dRole){
        return dRoleService.DeleteRole(dRole);
    }

    /**
     * 搜索单一指定角色
     * @param dRole 提供角色ID
     * @return 搜索出的角色
     */
    @Operation(summary = "搜索单一指定角色")
    @PostMapping("/selectRoleOne")
    public Result<DRole> SelectRoleOne(@RequestBody DRole dRole){
        return dRoleService.SelectRoleOne(dRole);
    }

    /**
     * 修改指定角色信息，修改角色权限
     * @param dRoleSelect 修改的角色
     * @return 无
     */
    @Operation(summary = "修改指定角色信息，修改角色权限")
    @PostMapping("/updateRoleOne")
    public Result<DRole> UpdateRoleOne(@RequestBody DRoleSelect dRoleSelect){
        return dRoleService.UpdateRoleOne(dRoleSelect);
    }



}
